<template>
  <div class="seller_ratings" id="seller_ratings">
    <div class="ratings_wrapper">
      <!--商家评分区-->
      <div class="overview">
        <div class="overview_left">
          <h1 class="score">{{seller.score}}</h1>
          <p class="title">综合评分</p>
          <p class="rank">高于周边商家{{seller.rankRate}}</p>
        </div>
        <div class="overview_right">
          <div class="score_wrapper">
            <span class="title">服务态度</span>
            <v-star :size="36" :score="seller.serviceScore"></v-star>
            <span class="score">{{seller.serviceScore}}</span>
          </div>
          <div class="score_wrapper">
            <span class="title">商品评分</span>
            <v-star :size="36" :score="seller.foodScore"></v-star>
            <span class="score">{{seller.foodScore}}</span>
          </div>
          <div class="score_wrapper">
            <span class="title">送达时间</span>
            <span class="deliveryTime">{{seller.deliveryTime}}分钟</span>
          </div>
        </div>
      </div>
      <!--分割层-->
      <v-split></v-split>
      <!--评论区-->
      <div class="seller_rating">
        <v-ratingselect :select-type="selectType" :only-content="onlyContent" :select-desc="selectDesc"
                        :ratings="ratings" v-on:select-type="changeSelect" v-on:content-toggle="changeContent">
        </v-ratingselect>
        <!--评价的内容 -->
        <div class="rating_wrapper">
          <ul v-show="ratings && ratings.length">
            <li v-for="rating in ratings" v-show="needShow(rating.rateType, rating.text)" class="rating_item">
              <div class="avatar">
                <img width="28" height="28" :src="rating.avatar" alt="userImage">
              </div>
              <div class="content">
                <h1 class="name">{{rating.username}}</h1>
                <div class="star_wrapper">
                  <v-star :size="24" :score="rating.score"></v-star>
                  <span class="delivery" v-show="rating.deliveryTime">{{rating.deliveryTime}}分钟送达</span>
                </div>
                <p class="text">{{rating.text}}</p>
                <div class="recommend" v-show="rating.recommend && rating.recommend.length">
                  <i class="iconfont" :class="[rating.rateType===0?'up':'down']">{{rating.rateType===0?'&#xe608;':'&#xe7b0;'}}</i>
                  <span class="item" v-for="item in rating.recommend">{{item}}</span>
                </div>
                <div class="time">
                  {{rating.rateTime | formate('YYYY-MM-DD hh:mm')}}
                </div>
              </div>
            </li>
          </ul>
          <div class="no_rating" v-show="!ratings || !ratings.length">
            暂无相关评价
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import BScroll from 'better-scroll'
  import split from 'components/split/split'
  import star from 'components/star/star'
  import ratingselect from 'components/ratingselect/ratingselect'
  const All = 2
  const ERR_OK = 0
  var Types = {'Types': All} /* 选择的评价的类型 */
  var onlyContent = {'onlyContent': false}
  export default {
    data() {
      return {
        ratings: [],
        selectType: Types,
        onlyContent: onlyContent,
        selectDesc: {
          all: '全部',
          positive: '满意',
          negative: '不满意'
        }
      }
    },
    props: {
      seller: Object
    },
    components: {
      'v-star': star,
      'v-split': split,
      'v-ratingselect': ratingselect
    },
    methods: {
      getGoodsData() {
        this.$http.get('/api/ratings/' + this.$route.params.id).then(function(res) {
          if (res.data.errno === ERR_OK) {
            this.ratings = res.data.data;
            this.$nextTick(function () {
              if(!this.scroll) {
                this.scroll = new BScroll(document.getElementById('seller_ratings'), {
                  click: true
                })
              }else {
                this.scroll.refresh()
              }
            })
          }
        })
      },
      needShow(type, text) {
        if(this.onlyContent.onlyContent && !text) {
          return false
        }
        if(this.selectType.Types === All) {
          return true
        }else {
          return type === this.selectType.Types
        }
      },
      changeSelect: function (type) {
        this.$nextTick(() => {
          this.scroll.refresh()
        })
      },
      changeContent(content) {
        this.$nextTick(() => {
          this.scroll.refresh()
        })
      }
    },
    mounted() {
      this.getGoodsData()
    }
  }
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
  $rgb: rgb(7, 17, 27);
  $rgba: rgba(7, 17, 27, 0.1);
  .seller_ratings {
    position: absolute;
    top: 174px;
    bottom: 0;
    left: 0;
    width: 100%;
    overflow: hidden;
    .overview {
      display: flex;
      padding: 18px 0;
      .overview_left {
        flex: 0 0 137px;
        width: 137px;
        padding-bottom: 6px;
        text-align: center;
        border-right: 1px solid $rgba;
        @media only screen and (max-width: 320px) {
          flex: 0 0 120px;
          width: 120px;
        }
        .score {
          line-height: 28px;
          font-size: 24px;
          color: rgb(255, 153, 0);
          margin-bottom: 6px;
        }
        .title {
          line-height: 12px;
          font-size: 12px;
          color: rgb(7, 17, 27);
          margin-bottom: 8px;
        }
        .rank {
          font-size: 10px;
          color: rgb(147, 153, 159);
          line-height: 10px;
        }
      }
      .overview_right {
        flex: 1;
        padding-left: 24px;
        @media only screen and (max-width: 320px) {
          padding-left: 10px;
        }
        .score_wrapper {
          line-height: 18px;
          margin-bottom: 8px;
          font-size: 0;
          .title {
            display: inline-block;
            line-height: 18px;
            font-size: 12px;
            color: $rgb;
          }
          .star_content {
            display: inline-block;
            margin: 0 12px;
            vertical-align: top;
          }
          .score {
            display: inline-block;
            font-size: 12px;
            line-height: 18px;
            vertical-align: top;
            color: rgb(255, 153, 0)
          }
          .deliveryTime {
            font-size: 12px;
            margin-left: 12px;
            color: rgb(147, 153, 159);
            line-height: 18px;
          }
        }
      }
    }
    .seller_rating {
      .rating_wrapper {
        padding: 0 18px;
        .rating_item {
          display: flex;
          padding: 18px 0;
          border-bottom: 1px solid $rgba;
          .avatar {
            flex: 0 0 28px;
            width: 28px;
            margin-right: 12px;
            img {
              border-radius: 50%;
            }
          }
          .content {
            flex: 1;
            position: relative;
            .name {
              line-height: 12px;
              font-size: 10px;
              color: $rgb;
              margin-bottom: 4px;
            }
            .star_wrapper {
              margin-bottom: 6px;
              font-size: 0;
              .star_content {
                display: inline-block;
                margin-right: 6px;
                vertical-align: top;
              }
              .delivery {
                display: inline-block;
                vertical-align: top;
                font-size: 10px;
                line-height: 12px;
                color: rgb(147, 153, 159);
              }
            }
            .text {
              line-height: 18px;
              color: $rgb;
              font-size: 12px;
              margin-bottom: 6px;
            }
            .recommend {
              line-height: 16px;
              font-size: 0;
              .iconfont, .item {
                display: inline-block;
                margin: 0 8px 4px 0;
                font-size: 9px;
              }
              .item {
                padding: 0 6px;
                border: 1px solid $rgba;
                border-radius: 1px;
                background-color: #fff;
              }
              .iconfont {
                font-size: 12px;
                line-height: 24px;
                margin-right: 2px;
                &.up {
                  color: rgb(0, 100, 220);
                }
                &.down {
                  color: rgb(147, 153, 159);
                }
              }
            }
            .time {
              position: absolute;
              top: 0;
              right: 0;
              line-height: 12px;
              font-size: 12px;
              color: rgb(147, 153, 159);
            }
          }
        }
        .no_rating {
          padding: 16px 0;
          font-size: 12px;
          color: rgb(147, 153, 159);
        }
      }
    }
  }
</style>